#ifndef __CACULATOR_HPP__
#define __CACULATOR_HPP__

#include<functional>
#include<vector>
#include"LogMessage.hpp"

typedef std::function<int(int, int)> func;

std::vector<std::pair<char, func>> tasks;

class Caculator {

public:
  Caculator() {}

  Caculator(int x, int y, func fun, int index)
    : _x(x)
    , _y(y)
    , _fun(fun)
    , _index(index)
  {}
  
  void operator()(const std::string& name) {

    // running task 
    LogMessage(NORMAL, _F, _L, "%s 执行任务 :: %d %c %d = %d", name.c_str(), _x, tasks[_index].first, _y, _fun(_x, _y)); 
     
  }

private:
  int _x;
  int _y;
  func _fun;
  int _index;

};

void loadCal() {
  func MyAdd = [](int x, int y) { return x + y; };
  func MySub = [](int x, int y) { return x - y; };
  func MyMul = [](int x, int y) { return x * y; };
  func MyDiv = [](int x, int y) { return x / y; };
  

  tasks.push_back(std::make_pair('+', MyAdd));
  tasks.push_back(std::make_pair('-', MySub));
  tasks.push_back(std::make_pair('*', MyMul));
  tasks.push_back(std::make_pair('/', MyDiv));
}

#endif
